package com.example.aipDriver.service;

import com.example.aipDriver.remote.ServiceOrderClient;
import com.example.aipDriver.remote.ServiceSsePushClient;
import com.example.internalcommon.constant.IdentityConstants;
import com.example.internalcommon.dto.ResponseResult;
import com.example.internalcommon.request.OrderRequest;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author lyra
 * @Date 2023/5/6 9:47
 **/
@Service
public class PayService {

    @Autowired
    ServiceSsePushClient serviceSsePushClient;

    @Autowired
    ServiceOrderClient serviceOrderClient;

    public ResponseResult pushPayInfo(Long orderId,String price,Long passengerId){
        // 封装消息
        JSONObject message = new JSONObject();
        message.put("price", price);
        message.put("orderId", orderId);

        // 修改订单状态
        OrderRequest orderRequest = new OrderRequest();
        orderRequest.setOrderId(orderId);

        serviceOrderClient.pushPayInfo(orderRequest);

        // 推送消息
        serviceSsePushClient.push(passengerId, IdentityConstants.PASSENGER_IDENTITY, message.toString());
        return ResponseResult.success();
    }
}
